<template>
  <div class="resumeMsgIndex">
    <div id="container">
      <div class="sidebar">
        <a class="btn_create" href="javascript:void(0)" @click="publicJob">发布新职位</a>
        <dl class="company_center_aside">
          <dt>我收到的简历</dt>
          <dd :class="showType == 'resume' && tab == 1 ? 'current btm':''" @click="changeTab(1)">
            <a href="javascript:void(0)">全部简历</a>
            <!-- <span>新</span> -->
          </dd>
          <dd :class="showType == 'resume' && tab == 2 ? 'current btm':''" @click="changeTab(2)">
            <a href="javascript:void(0)">已沟通简历</a>
          </dd>
          <dd :class="showType == 'resume' && tab == 3 ? 'current btm':''" @click="changeTab(3)">
            <a href="javascript:void(0)">不合适简历</a>
          </dd>
        </dl>
        <dl class="company_center_aside">
          <dt>我发布的职位</dt>
          <dd
            :class="showType == 'position' && company_status == 1 ? 'current btm':''"
            @click="changeStatus(1)"
          >
            <a href="javascript:void(0)">招聘中职位</a>
          </dd>
          <dd
            :class="showType == 'position' && company_status == 2 ? 'current btm':''"
            @click="changeStatus(2)"
          >
            <a href="javascript:void(0)">已下线职位</a>
          </dd>
        </dl>
      </div>
      <!-- end .sidebar -->
      <div class="content" v-if="showType == 'resume'">
        <dl class="company_center_content">
          <dt>
            <h1>
              <em></em>
              {{tab == 1 ? '全部简历':''}}
              {{tab == 2 ? '已沟通简历':''}}
              {{tab == 3 ? '不合适简历':''}}
              <span>（共{{total}}份）</span>
            </h1>
          </dt>
          <dd>
            <form action="autoFilterResumes.html" method="get" id="filterForm">
              <!-- <div class="filter_tip">
                系统将自动过滤学历、城市、工作年限
                <span>不符合</span> 要求的简历，自动过滤的简历若
                <span>15</span>
                日内未作处理，半城直聘将自动发送拒绝邮件至用户邮箱。
              </div>-->
              <!-- <div class="filter_actions">
                <label class="checkbox">
                  <input type="checkbox" />
                  <i></i>
                </label>
                <span>全选</span>
                <a id="resumeInterviewAll" href="javascript:;">待定</a>
                <a id="resumeRefuseAll" href="javascript:;">不合适</a>
                <div id="filter_btn">
                  筛选简历
                  <em></em>
                </div>
              </div>-->
              <!-- end .filter_actions -->
              <!-- <div class="filter_options dn">
                <dl>
                  <dt>简历状态：</dt>
                  <dd>
                    <a rel="-1" class="current" href="javascript:;">不限</a>
                    <a rel="1" href="javascript:;">未阅读</a>
                    <a rel="2" href="javascript:;">已阅读</a>
                    <a rel="3" href="javascript:;">已转发</a>
                    <input type="hidden" value="-1" name="resumeStatus" />
                  </dd>
                </dl>
                <dl>
                  <dt>简历形式：</dt>
                  <dd>
                    <a rel="-1" class="current" href="javascript:;">不限</a>
                    <a rel="0" href="javascript:;">附件简历</a>
                    <a rel="1" href="javascript:;">在线简历</a>
                    <input type="hidden" value="-1" name="resumeType" />
                  </dd>
                </dl>
                <dl>
                  <dt>工作经验：</dt>
                  <dd>
                    <a rel="-1" class="current" href="javascript:;">不限</a>
                    <a rel="1" href="javascript:;">应届毕业生</a>
                    <a rel="2" href="javascript:;">一年以下</a>
                    <a rel="3" href="javascript:;">1-3年</a>
                    <a rel="4" href="javascript:;">3-5年</a>
                    <a rel="5" href="javascript:;">5-10年</a>
                    <a rel="6" href="javascript:;">10年以上</a>
                    <input type="hidden" value="-1" name="workExp" />
                  </dd>
                </dl>
                <dl>
                  <dt>最低学历：</dt>
                  <dd>
                    <a rel="-1" class="current" href="javascript:;">不限</a>
                    <a rel="1" href="javascript:;">大专及以上</a>
                    <a rel="2" href="javascript:;">本科及以上</a>
                    <a rel="3" href="javascript:;">硕士及以上</a>
                    <a rel="4" href="javascript:;">博士及以上</a>
                    <input type="hidden" value="-1" name="eduExp" />
                  </dd>
                </dl>
                <input type="hidden" value="0" name="filterStatus" id="filterStatus" />
                <input type="hidden" value name="positionId" id="positionId" />
              </div>-->
              <!-- end .filter_options -->
              <ul class="reset resumeLists" v-if="resumeList.length">
                <li
                  v-for="(item,index) in resumeList"
                  :key="index"
                  data-id="1686182"
                  class="onlineResume"
                  @click="toWhere('resumeDetail',{worker_apply_id:item.worker_apply_id})"
                >
                  <div class="resumeShow">
                    <a title="预览在线简历" class="resumeImg" href="javascript:void(0)">
                      <img :src="item.worker.worker_avatar" />
                    </a>
                    <div class="resumeIntro">
                      <h3 class="unread">
                        <a
                          :title="item.worker.worker_nickname"
                          href="javascript:void(0)"
                        >{{item.worker.worker_nickname}}</a>
                        <!-- <em></em> -->
                      </h3>
                      <span class="fr">投递时间：{{item.time_create}}</span>
                      <div>
                        {{item.worker.worker_nickname}} / {{genderArr[Number(item.worker.worker_gender)]}} / {{educationArr[Number(item.worker.worker_education)]}} / {{item.worker.worker_experience > 0 ?(item.worker.worker_experience+'年'):'无经验'}}
                        <br />
                        出生日期：{{item.worker.worker_birthday}}
                      </div>
                      <div class="jdpublisher">
                        <span>
                          应聘职位：
                          <a
                            :title="item.job.position.position_title"
                            href="javascript:void(0)"
                          >{{item.job.position.position_title}}</a>
                        </span>
                      </div>
                    </div>
                    <!-- <div class="links">
                      <a
                        data-deliverid="1686182"
                        data-name="jason"
                        data-positionid="149594"
                        data-email="888888888@qq.com"
                        class="resume_notice"
                        href="javascript:void(0)"
                      >通知面试</a>
                      <a
                        data-deliverid="1686182"
                        class="resume_refuse"
                        href="javascript:void(0)"
                      >不合适</a>
                      <a
                        data-deliverid="1686182"
                        class="resume_caninterview"
                        href="javascript:void(0)"
                      >待定</a>
                      <a
                        data-positionname="随便写"
                        data-deliverid="1686182"
                        data-positionid="149594"
                        data-resumekey="1ccca806e13637f7b1a4560f80f08057"
                        data-forwardcount="1"
                        class="resume_forward"
                        href="javascript:void(0)"
                      >
                        转发
                        <span>(1人)</span>
                      </a>
                    </div>-->
                  </div>
                </li>
              </ul>
              <Empty v-if="resumeList.length == 0" content="暂无简历信息~"></Empty>
              <el-pagination
                v-if="resumeList.length"
                background
                layout="prev, pager, next"
                :page-size="10"
                :total="total"
                :current-page="page"
                @prev-click="changePage('prev','resume')"
                @next-click="changePage('next','resume')"
                @current-change="handlePage"
              ></el-pagination>
              <!-- end .resumeLists -->
            </form>
          </dd>
        </dl>
      </div>
      <div class="content" v-if="showType == 'position'">
        <dl class="company_center_content">
          <dt>
            <h1>
              <em></em>
              全部职位
              <span>
                （共
                <i style="color:#fff;font-style:normal" id="positionNumber">{{total}}</i>个）
              </span>
            </h1>
          </dt>
          <dd>
            <form id="searchForm">
              <input type="hidden" value="Publish" name="type" />
              <ul class="reset my_jobs" v-if="positionList.length">
                <li data-id="149594" v-for="(item,index) in positionList" :key="index">
                  <h3>
                    <a
                      :title="item.job_title||(item.position ? item.position.position_title:'')"
                      href="javascript:void(0)"
                      @click="toWhere('positionDetail',{job_id:item.job_id})"
                    >{{item.job_title||(item.position ? item.position.position_title:'')}}</a>
                    <!-- <span>[上海]</span> -->
                  </h3>
                  <!-- <span class="receivedResumeNo">
                    <a href="unHandleResumes.html?positionId=149594">应聘简历（1）</a>
                  </span>-->
                  <div>
                    {{jobTypeArr[(Number(item.job_type) - 1)]}}
                    / {{item.salary_unit == 4?'面议':(item.salary_min?(salary_unit[item.salary_unit] +':'+item.salary_min === item.salary_max ? item.salary_min : item.salary_min + '-' + item.salary_max):(salary_unit[item.salary_unit]+':'+item.salary))}}
                    /{{(item.job_experience_min == item.job_experience_max)?(item.job_experience_min == 0?'经验不限':(item.job_experience_max + '年')):(item.job_experience_min+'-'+item.job_experience_max+'年')}}
                    / {{educationArr[item.job_education]}}
                  </div>
                  <div class="c9">时间： {{item.time_update}}</div>
                  <div class="links">
                    <a
                      class="job_refresh"
                      href="javascript:void(0)"
                      @click="getJobShow(item.job_id)"
                      v-if="item.review_status == 1 &&item.company_status == 1"
                    >刷新</a>
                    <a class="job_edit" href="javascript:void(0)" @click="toWhere('publicJob',{jobId:item.job_id})">编辑</a>
                    <a
                      class="job_offline"
                      href="javascript:void(0)"
                      @click="offline(item.job_id)"
                      v-if="item.review_status == 1 &&item.company_status == 1"
                    >下线</a>
                    <a
                      class="job_del"
                      href="javascript:void(0)"
                      @click="doTop(item.job_id)"
                      v-if="item.review_status == 1&&item.company_status == 1"
                    >置顶</a>
                    <a
                      class="job_del"
                      href="javascript:void(0)"
                      @click="republic(item.job_id)"
                      v-if="item.company_status == 2"
                    >重新发布</a>
                  </div>
                </li>
              </ul>
              <Empty v-if="positionList.length == 0" content="暂无相关职位信息~"></Empty>
              <el-pagination
                v-if="positionList.length"
                background
                layout="prev, pager, next"
                :page-size="10"
                :total="total"
                :current-page="page"
                @prev-click="changePage('prev','position')"
                @next-click="changePage('next','position')"
                @current-change="handlePositionPage"
              ></el-pagination>
            </form>
          </dd>
        </dl>
      </div>
    </div>
    <el-dialog title="提示" :visible.sync="showTop" width="30%">
      <div class="topChoose">
        <el-radio
          v-for="(item,index) in topList"
          :key="index"
          v-model="hasChoose"
          :label="item.id"
        >置顶 {{item.time}} 天（{{Number(item.price) == 0 ? '免费' : (item.price + '元')}}）</el-radio>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="showTop = false">取 消</el-button>
        <el-button type="primary" @click="confirmTop">确 定</el-button>
      </span>
    </el-dialog>
    <!-- end #container -->
  </div>
</template>

<script>
import {
  Resume,
  JobManageList,
  JobShow,
  JobDescribe,
  JobOffline,
  TopList,
  BuyTopList
} from "~/api/allRequest";
import "./../../../public/js/jquery.1.10.1.min.js";
import "./../../../public/js/jquery.lib.min.js";
import "./../../../public/js/jquery.ui.datetimepicker.min.js";
import "./../../../public/js/received_resumes.min.js";
import "./../../../public/js/count.js";
import "./../../../public/js/core.min.js";
import "./../../../public/js/popup.min.js";
import Empty from "~/components/empty/empty";
export default {
  name: "resumeMsgIndex",
  data() {
    return {
      jobTypeArr: ["全职", "兼职", "钟点工"],
      salary_unit: ["", "元/月", "元/日", "元/时"],
      educationArr: [
        "学历不限",
        "小学",
        "初中",
        "中专",
        "高中",
        "大学专科",
        "大学本科",
        "硕士",
        "博士",
        "博士后",
        "其它"
      ],
      experienceArr: [
        "无经验",
        "1年",
        "2年",
        "3年",
        "4年",
        "5年",
        "6年",
        "7年",
        "8年",
        "9年",
        "10年"
      ],
      genderArr: ["未知", "男", "女"],
      page: 1,
      total: 0,
      tab: 1,
      resumeList: [],
      showType: "resume",
      company_status: 1,
      positionList: [],
      showTop: false,
      hasChoose: "0",
      topList: [],
      member_right: {}
    };
  },
  components: { Empty },
  beforeCreate() {},
  created() {
    this.$store.dispatch("changeTabName", "resumeMsgIndex");
  },
  beforeMount() {},
  mounted() {
    if (this.$route.params.showType) {
      this.showType = this.$route.params.showType;
    }
    if (this.showType == "position") {
      this.getPosition();
    } else if (this.showType == "resume") {
      this.getResume();
    }
  },
  beforeUpdate() {},
  updated() {},
  beforeDestroy() {},
  destroy() {},
  methods: {
    getResume() {
      this.showType = "resume";
      let page = this.page;
      let tab = this.tab;
      Resume({ page, tab })
        .then(result => {
          this.currentPage = result.current_page;
          this.resumeList = result.data;
          this.total = Number(result.total);
        })
        .catch(err => {
          console.log(err);
        });
    },
    changePage(type, kind) {
      let page = this.currentPage;
      if (type == "prev") {
        this.page = --page;
      } else if (type == "next") {
        this.page = ++page;
      }
      if (kind == "resume") {
        this.getResume();
      } else if (kind == "position") {
        this.getPosition();
      }
    },
    handlePage(val) {
      this.page = val;
      this.getResume();
    },
    changeTab(tab) {
      this.tab = tab;
      this.page = 1;
      this.getResume();
    },
    getPosition() {
      this.showType = "position";
      let page = this.page;
      let company_status = this.company_status;
      JobManageList({ page, company_status })
        .then(result => {
          this.currentPage = result.current_page;
          this.positionList = result.data;
          this.total = Number(result.total);
          this.member_right = result.member_right;
        })
        .catch(err => {});
    },
    changeStatus(status) {
      this.company_status = status;
      this.page = 1;
      this.getPosition();
    },
    handlePositionPage(val) {
      this.page = val;
      this.getPosition();
    },
    getJobShow(job_id) {
      JobShow({ job_id })
        .then(result => {
          let { refresh_job_times } = result.member_right;
          if (refresh_job_times > 0) {
            this.$confirm(
              `是否扣除1次刷新职位权益,当前可免费刷新${refresh_job_times}次，刷新成功后即会扣除`
            )
              .then(data => {
                //对福利数据进行处理
                if(result.tag){
                  let temp = []
                  for(let i =0 ;i < result.tag.length;i++){
                    temp.push(result.tag[i].tag_type)
                  }
                  result.tag = temp.join()
                }
                JobDescribe(result)
                  .then(result => {
                    this.$message.success("刷新成功");
                  })
                  .catch(err => {
                    console.log(err);
                  });
              })
              .catch(err => {
                console.log(err);
              });
          } else {
            this.$confirm(`当前可刷新职位0次,是否前往我的权益购买`)
              .then(data => {
                this.$router.push({ name: "equityMain" });
              })
              .catch(err => {
                console.log(err);
              });
          }
        })
        .catch(err => {
          console.log(err);
        });
    },
    offline(job_id) {
      JobOffline({ job_id, status: 2 })
        .then(result => {
          this.$message.success("下线成功");
          setTimeout(() => {
            this.page = 1;
            this.getPosition();
          }, 1000);
        })
        .catch(err => {
          console.log(err);
        });
    },
    doTop(job_id) {
      TopList()
        .then(result => {
          //默认选中第一个
          // 过滤check 为false的数据
          let temp = [];
          let hasBiao = false;
          for (let i = 0; i < result.topList.length; i++) {
            if (result.topList[i].check) {
              if (!hasBiao) {
                this.hasChoose = result.topList[i].id;
                hasBiao = true;
              }
              temp.push(result.topList[i]);
            }
          }
          this.balance = result.company.balance;
          this.topList = temp;
          this.job_id = job_id;
        })
        .catch(err => {
          console.log(err);
        });
      this.showTop = true;
    },
    confirmTop() {
      let needPrice = "";
      let hasChoose = this.hasChoose;
      let topList = this.topList;
      let balance = this.balance;
      let job_id = this.job_id;
      let needTime = "";
      let toplist_id = "";
      for (let i = 0; i < topList.length; i++) {
        if (hasChoose == topList[i].id) {
          needPrice = topList[i].price;
          needTime = topList[i].time;
          toplist_id = topList[i].id;
        }
      }
      if (needPrice && Number(needPrice) <= balance) {
        this.$confirm(
          `是否支付${Number(
            needPrice
          )}元置顶${needTime}天,当前账户余额：${Number(balance)}元`
        )
          .then(data => {
            BuyTopList({ toplist_id, job_id })
              .then(result => {
                if (result) {
                  this.$message.success("置顶成功");
                  setTimeout(() => {
                    this.showTop = false;
                    this.page = 1;
                    this.getPosition();
                  }, 1000);
                }
              })
              .catch(err => {
                console.log(err);
              });
          })
          .catch(err => {
            console.log(err);
          });
      } else if (needPrice && Number(needPrice) > balance) {
        this.$confirm(`当前账户余额不足（${Number(balance)}元),是否立即充值`)
          .then(data => {
            this.$message.success("小程序充值");
          })
          .catch(err => {
            console.log(err);
          });
      } else if (needPrice == 0) {
        BuyTopList({ toplist_id, job_id })
          .then(result => {
            if (result) {
              this.$message.success("置顶成功");
              setTimeout(() => {
                this.showTop = false;
                this.page = 1;
                this.getPosition();
              }, 1000);
            }
          })
          .catch(err => {
            console.log(err);
          });
      }
    },
    publicJob() {
      let member_right = this.member_right;
      if (member_right.publish_job_times > 0) {
        this.$confirm(
          `是否扣除1次发布职位权益,当前可免费发布${member_right.publish_job_times}次，重新上线成功后即会扣除`
        )
          .then(data => {
            this.$router.push({ name: "publicJob" });
          })
          .catch(err => {
            console.log(err);
          });
      } else {
        this.$confirm(`当前可刷新职位0次,是否前往我的权益购买`)
          .then(data => {
            this.$router.push({ name: "equityMain" });
          })
          .catch(err => {
            console.log(err);
          });
      }
    },
    republic(job_id) {
      let member_right = this.member_right;
      if (member_right.publish_job_times > 0) {
        this.$confirm(
          `是否扣除1次发布职位权益,当前可免费发布${member_right.publish_job_times}次，重新上线成功后即会扣除`
        )
          .then(data => {
            JobOffline({ job_id, status: 1 })
              .then(result => {
                this.$message.success("发布成功");
                setTimeout(() => {
                  this.page = 1;
                  this.getPosition();
                }, 1000);
              })
              .catch(err => {
                console.log(err);
              });
          })
          .catch(err => {
            console.log(err);
          });
      } else {
        this.$confirm(`当前可刷新职位0次,是否前往我的权益购买`)
          .then(data => {
            this.$router.push({ name: "equityMain" });
          })
          .catch(err => {
            console.log(err);
          });
      }
    },
    toWhere(name, json) {
      if (json) {
        this.$router.push({ name, query: json });
      } else {
        this.$router.push({ name });
      }
    }
  }
};
</script>

<style scoped lang="less">
@import "./../../../public/less/main.less";
.resumeMsgIndex {
  min-height: 80vh;

  .topChoose {
    width: 80%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: flex-start;
  }
}
</style>
